<%@page import="com.library.service.impl.BookServiceImpl"%>
<%@page import="com.library.bean.Book"%>
<%@page import="java.util.List"%>
<%@page import="com.library.bean.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% 
	if(session.getAttribute("loginUser") == null){
		response.sendRedirect("login.jsp");
		return;
	}
	
/* 	if(request.getAttribute("books") == null){
		request.setAttribute("books",new BookServiceImpl().getAllBook());//当直接访问success.jsp时，也会从数据库中查询所有书本的信息
	}  */
	if(request.getAttribute("page") == null){
		request.setAttribute("page",new BookServiceImpl().getAllBook(1, 5));
	}

%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	table a{
		text-decoration:none
	}
</style>
</head>
<body>
	登录成功,欢迎${loginUser.realName}
	<form action="searchBook.do" method="GET">
		<input type="text" name="keyword">
		<input type="submit" value="搜索">
	</form>
	<a href="addBook.jsp" target="_blank">添加书本</a>
	<table border="1" width="600">
		<tr>
			<td>序号</td>
			<td>书id</td>
			<td>书名</td>
			<td>作者</td>
			<td>库存</td>
			<td>操作</td>
		</tr>
		
		<c:forEach items="${page.data}" var="book" varStatus="status">
			<tr>
				<td>${status.count}</td>
				<td>${book.bookId}</td>
				<td>${book.bookName}</td>
				<td>${book.bookWriter}</td>
				<td>${book.bookNum}</td>
				<td>
					<a href="bookServlet.do?bookId=${book.bookId}&opt=0">删除</a>
					<a href="getBookInfor.do?bookId=${book.bookId}">修改</a>
				</td>
			</tr>
		</c:forEach>
		
	</table>
	<div>
		<a href="getAllBooks.do?pageNum=1&pageSize=5">首页</a>
		<c:if test="${page.hasPrev}">
			<a href="getAllBooks.do?pageNum=${page.pageNum -1}&pageSize=5">上一页</a>
		</c:if>
		<c:if test="${page.hasNext}">
			<a href="getAllBooks.do?pageNum=${page.pageNum +1}&pageSize=5">下一页</a>
		</c:if>
		<a href="getAllBooks.do?pageNum=${page.totalPageNum}&pageSize=5">尾页</a>
		总数据:${page.totalRows}
		总页数:${page.totalPageNum}
	</div>
</body>
</html>